package com.school_admin.mapper;

import com.school_admin.entity.Post;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author
 * @since 2024-03-18
 */
@Mapper
public interface PostMapper extends BaseMapper<Post> {
    @MapKey("postId")
    List<Map<String,Object>> getPostListWeb(int start, int pageSize);
    Integer getPostListWebCount();

    @MapKey("postId")
    List<Map<String, Object>> queryPost(String postId);
    // 更新点赞量
    @Update("UPDATE sc_post SET `like` = `like` + 1 WHERE postId = #{postId}")
    void updatePostLikeCount(int like,String postId);
    // 更新收藏量
    @Update("UPDATE sc_post SET `collection` = `collection` + 1 WHERE postId = #{postId}")
    void updatePostCollectionCount(String postId);
    // 更新浏览量
    @Update("UPDATE sc_post SET `view` = `view` + 1 WHERE postId = #{postId}")
    void updateViewCount(String postId);

    @Select("SELECT postId,title FROM sc_post ORDER BY `time` DESC LIMIT 10")
    List<Post> getNewList();
    @MapKey("postId")
    List<Map<String,Object>> getSearchList(String value, int start,int pageSize);
    Integer getSearchListCount(String value);
    @MapKey("postId")
    List<Map<String, Object>> getPostListAdmin(int start, int pageSize);
    Integer getPostListAdminCount();
    @MapKey("postId")
    List<Map<String, Object>> getSearchListAdmin(String keyWord, int start, int pageSize);
    Integer getSearchListAdminCount(String keyWord);
    @Update("UPDATE sc_post SET `isPublic` = #{isPublic} WHERE postId = #{postId}")
    boolean changePostStatus(int isPublic,String postId);
    @Select("SELECT tags FROM sc_post WHERE deleted = 0 ")
    List<String> getLabel();
    @MapKey("postId")
    List<Map<String, Object>> getSearchListForTag(String value, int start, int pageSize);
    Integer getSearchListForTagCount(String value);

    @Select("SELECT tag FROM `sc_user` WHERE uid = #{uid}")
    String getUsertags(String uid);

    @MapKey("postId")
    List<Map<String, Object>> getPostListWebByTag(int start, int pageSize, String tag);
    @MapKey("postId")
    List<Map<String, Object>> random(int start, int pageSize);

    Integer getPostListTagCount();
}
